<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Kesillo\Core;

class View 
{
    private $_file;
    private $_path;
    
    /*
     * Factory method. We dotn specify any "Views" on this method so that we
     * can append more "views" without having to instantiate a new class everytime.
     * 
     * $data is the app's "metadata" This is all we pass to the factory(). After that
     * we just call the render() to render the view. Nothing special.
     */
    public static function factory()
    {
        return new View();
    }
    
    /*
     * Basic constructor. We jsut set $data
     */
    public function __construct()
    {
        
    }
    
    /*
     * This is pretty much where we find the file to include. This could use some
     * work to make sure we actually find a file that exists, instead of assuming 
     * it does.
     */
    private function setFileName($file = NULL)
    {
        return AppPath.'Views'.DIRECTORY_SEPARATOR.$file.EXT;
    }
    
    /*
     * Just include the file we want.
     */
    public function render($file = NULL)
    {
        if($file !== NULL)
            $this->_path = $this->setFileName($file);
        
        include $this->_path;
    }
}